package oa.web.controller;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import oa.core.Constant;
import oa.core.MySession;
import oa.web.pojo.Employee;
import oa.web.service.SalaryService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class Salary {
	
	@Autowired SalaryService salaryService;
	
	@RequestMapping("/personSalary")
	public String personSalary(HttpServletRequest req, HttpServletResponse rep, ModelMap map){
		Employee emp = this.getEmp(req);
		map.addAttribute("emp", emp);
		return "mySalary";
	}
	
	@RequestMapping("/depSalary")
	public String depSalary(HttpServletRequest req, HttpServletResponse rep, ModelMap map){
		Employee emp = this.getEmp(req);
		List<Employee> empList = salaryService.getByManagerId(emp.getId());
		map.addAttribute("empList", empList);
		return "depSalary";
	}
	
	public Employee getEmp(HttpServletRequest req) {
		HttpSession session = MySession.getInstance(req);
		Employee emp = null;
		try{
			emp= (Employee)session.getAttribute(Constant.CURRENT_USER);
		}catch(Exception e){
			e.printStackTrace();
		}
		return emp;
	}
}
